package Day05;

import java.sql.SQLOutput;
import java.util.Arrays;

public class Text6 {
    public static void main(String[] args) {
        //给定一个整型数组, 实现冒泡排序(升序排序)
        int[] a = {8, 7, 5, 3, 6, 2};
        BubbleSort(a);
        System.out.println(Arrays.toString(a));

    }
    public static void BubbleSort(int[] a){
        for(int i = 0; i < a.length - 1; i++){
            boolean flag = false;
            for(int j = 0; j < a.length -1 -i; j++){
                if(a[j] > a[j + 1]){
                    int temp = a[j+1];
                    a[j+1] = a[j];
                    a[j] = temp;
                    flag = true;
                }
            }
            if(flag == false){
                break;
            }
        }
    }


}
